<?php
namespace app\mobile\service;

use think\facade\Db;
use think\facade\Config;

/**
 *
 * @package app\admin\service
 */
class HornService
{

    public function message($horn_devid,$message){

        $data = [
            'cmd' => 'voice',
            'msg' =>$message,
            'msgid' => time().rand(1,999999)
        ];
        $string = json_encode($data, true);
        $map = [
            'sbx_id' => $horn_devid,//机器编号
            'agent_id' => $string,
        ];
        $url = "http://cs.mqlinks.com/txmsgpush/";
        $this->curl_request($url, json_encode($map, true));

    }






    function curl_request($url,  $data = '', $second =30){
        //curl_init函数初始化请求会话，可以传递一个请求地址参数。
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_TIMEOUT, $second);
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
        //如果发送post请求，需要设置请求方式和请求参数
        curl_setopt($ch, CURLOPT_POST, true);
        //请求参数
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

        //curl请求默认返回true false,想要返回结果，需要设置
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // ③curl_exec函数发送请求，有返回值
        $res = curl_exec($ch);
        // ④curl_close关闭请求会话
        curl_close($ch);
        return $res;
    }

}


